package com.tao.controller.webpageController;

import com.tao.pojo.dto.PageSelectSetmealDto;
import com.tao.pojo.dto.SetmealDto;
import com.tao.result.Result;
import com.tao.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "http://localhost:7000/")
@RestController
@Slf4j
@RequestMapping("/webPage/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    @PostMapping("/add")
    public Result addSetmealController(@RequestBody SetmealDto setmealDto) {
        log.info("接收到前端数据：{}", setmealDto);
        setmealService.addSetmealService(setmealDto);
        return Result.success();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(setmealService.getById(id));
    }

    @DeleteMapping("/delete")
    public Result deleteSetmeal(@RequestParam List<Integer> ids){
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }

    @PutMapping("/update")
    public Result updateSetmeal(@RequestBody SetmealDto setmealDto){
        setmealService.updateSetmeal(setmealDto);
        return Result.success("修改成功");
    }

    @PostMapping("/status/{status}")
    public Result upadteStatus(Integer id,@PathVariable Integer status){
        setmealService.updateStatus(id,status);
        return Result.success();
    }

    @GetMapping("/page")
    public Result pageSelect( PageSelectSetmealDto pageSelectSetmealDto){
        return Result.success(setmealService.pageSelect(pageSelectSetmealDto));
    }

    @GetMapping("/selectByCategoryId")
    public Result selectByCategoryId(Integer categoryId){
        return Result.success(setmealService.selectByCategoryId(categoryId));
    }

    @GetMapping("/product/{id}")
    public Result selectSetmealProduct(@PathVariable Integer id){
        return Result.success(setmealService.selectSetmealProduct(id));
    }
}
